using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using elibrary.Models;

namespace elibrary.Classes
{
	public class AppGlobals
	{
		public static DataContext dataContext = new DataContext();
        public static HttpApplicationState Application;
        public static PageRoute[] routes = new PageRoute[]
        {
            new PageRoute { name="homepage", url="", defaults=new {controller="Marketplace", action="index"} },
            new PageRoute { name="login", url="login", defaults=new {controller="UserManagement", action="login"} },
            new PageRoute { name="logout", url="logout", defaults=new {controller="UserManagement", action="logout"} },
            new PageRoute { name="register", url="register", defaults=new {controller="UserManagement", action="register"} },
            new PageRoute { name="forget_password", url="forget-password", defaults=new {controller="UserManagement", action="forgetPassword"} },
            new PageRoute { name="my_profile", url="my-profile", defaults=new {controller="UserManagement", action="accountSettings"} },
            new PageRoute { name="my_books", url="my-books", defaults=new {controller="Administrative", action="manageUserBooks"} },
            new PageRoute { name="my_books_add", url="my-books/add", defaults=new {controller="Administrative", action="addBook"} },
            new PageRoute { name="my_books_edit", url="my-books/edit/{id}", defaults=new {controller="Administrative", action="editBook"} },
            new PageRoute { name="my_cart", url="my-cart", defaults=new {controller="OrderManagement", action="viewCart"} },
            new PageRoute { name="my_order", url="my-order", defaults=new {controller="OrderManagement", action="viewPendingOrder"} },
            new PageRoute { name="shopping_history", url="shopping-history", defaults=new {controller="OrderManagement", action="shoppingHistory"} },
            new PageRoute { name="contact_us", url="contact-us", defaults=new {controller="Marketplace", action="contactUs"} },
            new PageRoute { name="browsing_book_page", url="page/{page}", defaults=new {controller="Marketplace", action="index"} },
            new PageRoute { name="viewing_book_id", url="id/{id}", defaults=new {controller="Marketplace", action="view"} },
            new PageRoute { name="user_management", url="user-management/{action}", defaults=new {controller="UserManagement", action="index"} },
            new PageRoute { name="dministrative_category_def", url="administrative/categories", defaults=new {controller="Administrative", action="manageCategories"} },
            new PageRoute { name="administrative_book_def", url="administrative/books", defaults=new {controller="Administrative", action="manageBooks"} },
            new PageRoute { name="administrative_book_add", url="administrative/books/add", defaults=new {controller="Administrative", action="addBook"} },
            new PageRoute { name="administrative_book_edit", url="administrative/books/edit/{id}", defaults=new {controller="Administrative", action="editBook"} },
            new PageRoute { name="administrative_book_image", url="administrative/books/images/{id}", defaults=new {controller="Administrative", action="manageBookImages"} },
            new PageRoute { name="administrative_feedback_def", url="administrative/feedbacks", defaults=new {controller="Administrative", action="manageFeedback"} },
            new PageRoute { name="administrative", url="administrative/{action}", defaults=new {controller="Administrative", action="index"} },
            new PageRoute { name="order_management_view_order", url="order-management/orders/view/id/{id}", defaults=new {controller="OrderManagement", action="viewOrderItems"} },
            new PageRoute { name="order_management_payments", url="order-management/payments", defaults=new {controller="OrderManagement", action="managePayment"} },
            new PageRoute { name="order_management_orders", url="order-management/orders", defaults=new {controller="OrderManagement", action="manageOrder"} },
            new PageRoute { name="order_management", url="order-management/{action}", defaults=new {controller="OrderManagement", action="index"} },
            new PageRoute { name="marketplace_view_page", url="marketplace/page/{page}", defaults=new {controller="Marketplace", action="index"} },
            new PageRoute { name="marketplace", url="marketplace/{action}", defaults=new {controller="Marketplace", action="index"} },
            new PageRoute { name="default", url="{controller}/{action}", defaults=new {controller="Marketplace", action="index"} }
        };

		public static T glbs<T>(string n, T def)
		{
			object w = Application[n];
			def = w != null && w is T ? (T) w : def;

			return def;
		}
	}
}